package LeetCodeP;



public class Soluction1108 {

    public static String defangIPaddr(String address) {
        char[] temp = address.toCharArray();
        char[] result = new char[temp.length+3*2];
        int j = 0;
        for(int i = 0;i<temp.length;i++,j++){
            if('.' == temp[i]){
                result[j++]='[';
                result[j++]='.';
                result[j]=']';
            }else{
                result[j]=temp[i];
            }
        }
        return String.valueOf(result);
    }



    public static String defangIPaddr01(String address) {
        StringBuffer stringBuffer = new StringBuffer();

        for (int i=0;i<address.length();i++){

            if (address.charAt(i)=='.'){
                stringBuffer.append("[.]");
                continue;
            }
            stringBuffer.append(address.charAt(i));
        }
        String s = stringBuffer.toString();
        System.out.println(s);

        return s;
    }



    public static void main(String[] args) {
        String address = "255.100.50.0";
        defangIPaddr01(address);
    }

}
